<template>
    <div class="main">
        <div class="main-box">
            <el-table
                    :data="tableData"
                    style="width: 100%"
                    height="500">
                <el-table-column
                        label="日期"
                        width="300">
                    <template slot-scope="scope">
                        <div>{{scope.row.createTime|timestampToTime}}</div>
                    </template>
                </el-table-column>
                <el-table-column
                        prop="title"
                        label="新闻标题">
                </el-table-column>
                <el-table-column
                        label="操作"
                        width="100">
                    <template slot-scope="scope">
                        <el-button @click="goToDetail(scope.row.id)" type="text" size="small">查看详情</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
        </div>
    </div>
</template>

<script>
    import Pagination from '../components/Pagination'

    export default {
        name: "Resource",
        // 注册组件
        components: {
            Pagination
        },
        data() {
            return {
                tableData: [],
                formInline: {
                    pageIndex: 1,
                    pageSize: 10,
                    typeId: 2,
                    title: ''
                },
                pageparm: {
                    currentPage: 1,
                    pageSize: 10,
                    total: 10
                },
            }
        },
        created() {
            this.getData(this.formInline)
        },
        methods: {
            getData(prarm) {
                this.$axios.get("/api/information/query", {
                    params: prarm
                })
                    .then(res => {
                        this.tableData = res.data.data.resultList
                        this.pageparm.total = res.data.data.totalCount
                    }).catch(err => {
                    return Promise.reject(err);
                });
            },
            // 分页插件事件
            callFather(parm) {
                this.formInline.pageIndex = parm.currentPage
                this.formInline.pageSize = parm.pageSize
                this.getData(this.formInline)
            },
            goToDetail(id) {
                this.$router.push(
                    {
                        path:'/info/details',
                        query:{
                            id: id
                        }
                    })
            }
        }
    }
</script>

<style scoped>
    .main-box {
        background-color: #ffffff;
        padding-bottom: 20px;
    }

    .main {
        margin: 0 auto;
        max-width: 1225px;
    }
</style>
